/**
 * Copyright &copy; 2016-2017 <a href="http://git.oschina.net/whoamien/backend_management">Backend Management</a> All rights reserved.
 */
package com.xw.app.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xw.app.dao.GeneratorConfigDAO;
import com.xw.app.model.GeneratorConfig;
import com.xw.app.service.GeneratorConfigService;
import com.xw.framework.base.service.BaseServiceImpl;

/**
 * The Class GeneratorConfigServiceImpl.
 *
 * @author Xi Wei
 */
@Service
@Transactional
public class GeneratorConfigServiceImpl extends BaseServiceImpl<GeneratorConfig, Long> implements GeneratorConfigService {

	@Autowired
	private GeneratorConfigDAO generatorConfigDAO;
	
	/* (non-Javadoc)
	 * @see com.xw.app.service.GeneratorConfigService#checkConfigNameExist(com.xw.app.model.GeneratorConfig)
	 */
	@Override
	@Transactional(readOnly=true)
	public boolean checkConfigNameExist(GeneratorConfig generatorConfig) {
		if(generatorConfig == null){
			return false;
		}
		List<GeneratorConfig> list = null;
		if(generatorConfig.getId() == null){
			list = generatorConfigDAO.findByConfigName(generatorConfig.getConfigName());
		}else{
			list = generatorConfigDAO.findByConfigNameAndIdNot(generatorConfig.getConfigName(),generatorConfig.getId());
		}
		if(list == null || list.isEmpty()){
			return false;
		}
		return true;
	}
}
